<?php
/*公用函数库*/


function _get_userlogo_url($userlogo){

	if (strstr($userlogo, "http://"))
	{
		return $userlogo;
	}
    return $userlogo? '/'.trim($userlogo,'/') : _get_cfg_path('images').'imghead.jpg';

}

function _get_companylogo_url($logo){

	if (strstr($logo, "http://"))
	{
		return $logo;
	}
    return $logo? '/'.trim($logo,'/') : _get_cfg_path('images').'imghead2.jpg';

}

function _get_login_agent_user(){
	$CI =& get_instance();

	$agentUser = $CI->cache->get('agentUser');
	if(!empty($agentUser))
		return $agentUser;
	else
		return $CI->loginUser;
}

function _get_image_url($img){

	if (strstr($img, "http://"))
	{
		return $img;
	}
    return $img? '/'.trim($img,'/') : '';

}

function _check_password_safe($pwd){
	$res = 1;
	if(preg_match('/^[0-9]{1,6}$/', $pwd))
		$res = 1;
	else if(preg_match('/^([a-z]+(?=[0-9])|[0-9]+(?=[a-z]))[a-z0-9]+$/i',$pwd))
		$res = 3;
	else
		$res = 2;

	return $res;
}

function _get_timehello()
{
	$res = '';
	$arrHello = _get_config('timehello');
	$h = date('H',time());
	if($h>=6 && $h< 12)
		$res = $arrHello[1];
	else if($h>=12 && $h< 14)
		$res = $arrHello[2];
	else if($h>=14 && $h< 18)
		$res = $arrHello[3];
	else
		$res = $arrHello[4];

	return $res;
}



/**
 * 提示并跳转
 * @param mixed
 *      $txt    提示信息
 *      $link   跳转地址
 *      $type   类型
 *              1----提示并点击跳转
 *              2----提示并在N秒后自动跳转
 *              3----仅提示信息，有按钮
 *              4----仅提示信息，无按钮，N秒后消失
 *      $tipsTime 自动跳转时间
 * @return null
 * @autor yc
 * @creattime 2014-06-18
 */
function msg($txt='', $link='', $type=2 , $tipsTime=2000) {
	echo '<html><head><meta charset="utf-8"><body>';
	echo '<link href="'._get_cfg_path('admin_css').'right.css" rel="stylesheet">';
	echo '<script language="javascript" src="'. _get_cfg_path('admin_css').'../js/jquery-1.8.0.min.js"></script>';
	echo '<script language="javascript" src="'. _get_cfg_path('admin_css').'../js/main.js"></script>';
	echo "<script language=\"JavaScript\">";
	switch($type){
		case 1://提示并点击跳转
			$paras = "{title:'提示信息',content:'".$txt."',buttons:{'确定'：'urlTips(".$link.")','取消':'closePop()'},url:'".$link."'}";
			echo "tipsPop(".$paras.");";
			break;
		case 2://提示并在N秒后自动跳转
			$paras = "{title:'提示信息',content:'".$txt."',time:'".$tipsTime."',url:'".$link."'}";
			echo "tipsPop(".$paras.");";
			break;
		case 3://仅提示信息，有按钮
			$paras = "{title:'提示信息',content:'".$txt."',buttons:{'确定'：'closePop()'}}";
			echo "tipsPop(".$paras.");";
			break;
		case 4://仅提示信息，无按钮，N秒后消失
			$paras = "{title:'提示信息',content:'".$txt."',time:'".$tipsTime."'}";
			echo "tipsPop(".$paras.");";
			break;

	}
	echo "</script>";
	echo '</body></head></html>';exit;
}

/*文件上传*/
function upload($str,$picName){
	$CI                         =& get_instance();
	$config['upload_path']      = '../uploads/';
	$config['allowed_types']    = empty($str)?'gif|jpg|png':$str;
	$config['max_size']         = '204800';
	$config['max_width']        = '102400';
	$config['max_height']       = '76800';

	$CI->load->library('upload');
	$fileUpload = new CI_Upload($config);

	if ( ! $fileUpload->do_upload($picName,time())){
		$data = array(
				'error' => $fileUpload->display_errors()
		);
		return $data;
	}else{
		$data = array(
				'upload_data' =>'http://'.$_SERVER['HTTP_HOST'].$_SERVER['QUERY_STRING'].'/uploads/'.$fileUpload->file_name
		);
		return $data;
	}
}
?>